import request from '@/utils/request'
import { Axios, AxiosResponse } from 'axios'
import { AddTaskParams, EditReminderLevelParams, EditTaskParams } from './type'

// 项目用户相关的请求地址
enum Task_API {
  GET_TODAY_TASK = '/transaction_assistant/task/getTodayTask',
  GET_ALL_TASK = '/transaction_assistant/task/getAllTask/{completionStatus}',
  POST_ADD_TODAY_TASK = '/transaction_assistant/task/addTodayTask',
  PUT_EDIT_TODAY_TASK = '/transaction_assistant/task/editTodayTask',
  PUT_EDIT_REMINDER_LEVEL = '/transaction_assistant/task/editReminderLevel',
  DELETE_TASK = '/transaction_assistant/task/deleteTask/{id}',
  GET_WEEK_ALL_TASK = '/transaction_assistant/task/getWeekAllInfo',
  Get_Today_Progress = '/transaction_assistant/task/today-progress',
  PUT_TODAY_STATUS_CHANGE = '/transaction_assistant/task/changeStatus',
}

/**
 * 获取今日所有事务信息
 */
export const getTodayTask = () => {
  return request.get<any, AxiosResponse<any>>(Task_API.GET_TODAY_TASK)
}

/**
 * 获取指定状态下的事务信息
 */
export const getAllTask = (completionStatus: number) => {
  return request.get<any, AxiosResponse<any>>(
    Task_API.GET_ALL_TASK.replace('{completionStatus}', completionStatus),
  )
}

/**
 * 添加今日事务信息
 */
export const addTask = (params: AddTaskParams) =>
  request.post<any, AxiosResponse<any>>(Task_API.POST_ADD_TODAY_TASK, params)

/**
 * 修改今日事务信息
 */
export const editTodayTask = (params: EditTaskParams) => {
  return request.put<any, AxiosResponse<any>>(
    Task_API.PUT_EDIT_TODAY_TASK,
    params,
  )
}

/**
 * 修改提醒级别
 */
export const editReminderLevel = (params: EditReminderLevelParams) => {
  return request.put<any, AxiosResponse<any>>(
    Task_API.PUT_EDIT_REMINDER_LEVEL,
    params,
  )
}

/**
 * 修改状态
 */
export const changeStatus = (params: any) => {
  return request.put<any, AxiosResponse<any>>(
    Task_API.PUT_TODAY_STATUS_CHANGE,
    params,
  )
}

/**
 * 删除今日事务
 */
export const deleteTask = (id: number) => {
  return request.delete<any, AxiosResponse<any>>(
    Task_API.DELETE_TASK.replace('{id}', id),
  )
}

/**
 * 获取本周全部事务
 */
export const getWeekAllInfo = (status?: number) => {
  return request.get<any, AxiosResponse<any>>(Task_API.GET_WEEK_ALL_TASK, {
    params: { status: status },
  })
}

/**
 * 获取今日完成进度
 */
export const getTodayProgress = () => {
  return request.get<any, AxiosResponse<any>>(Task_API.Get_Today_Progress)
}
